/**
 * 配置路由
 */
import Vue from 'vue'
import VueRouter from 'vue-router'

//使用路由插件
Vue.use(VueRouter)

//解决push路由跳转重复报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, resolve, reject) {
    if (resolve && reject) {
        return originalPush.call(this, location, resolve, reject)
    }
    return originalPush.call(this, location, () => { }, () => { })
}
//解决replace路由跳转重复报错
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location, onResolve, onReject) {
    if (onResolve && onReject) {
        return originalReplace.call(this, location, onResolve, onReject)
    }
    return originalReplace.call(this, location, () => { }, () => { })
}

//导入路由组件
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'

//配置路由
export default new VueRouter({
    routes: [
        {
            path: '/home',
            component: Home,
            meta: { showFooter: true }
        },
        {
            path: '/login',
            component: Login,
            meta: { showFooter: false }
        },
        {
            path: '/register',
            component: Register,
            meta: { showFooter: false }
        },
        {
            name: 'search',
            path: '/search/:keyword?',
            component: Search,
            meta: { showFooter: true }
        },
        {
            path: '/',
            redirect: '/home'
        }
    ]
})